<?php
include("../utility/connection.php");
include("../model/mBarang.php");
session_start();

if($_SERVER["REQUEST_METHOD"] == "POST") {
    unset($_SESSION['kategori']);
    unset($_SESSION['errMessage']);
    unset($_SESSION['startNum']);
    unset($_SESSION['endNum']);
    unset($_SESSION['curPage']);
    
    $kategori = trim(mysql_real_escape_string($_POST["hidKategori"]));
    $startNum = trim(mysql_real_escape_string($_POST["hidStartNum"]));
    $endNum = trim(mysql_real_escape_string($_POST["hidEndNum"]));
    $curPage = trim(mysql_real_escape_string($_POST["hidCurPage"]));
    //$totalPage = trim(mysql_real_escape_string($_POST["hidTotalPage"]));
    
    $count = 0;
    if ($kategori != 10) {
        // bukan all / semua barang
        $result = fnBrgByKategoriAndRange($kategori, $startNum, $endNum);
        $count = mysql_num_rows($result);
    } else if ($kategori == 10) {
        // all / semua barang
        $count = -1;
    }
    
    if ($count > 0) {
        // barang sesuai kategori ditemukan
        $_SESSION['kategori']=$kategori;
        $_SESSION['startNum']=$startNum;
        $_SESSION['endNum']=$endNum;
        $_SESSION['curPage']=$curPage;
        header("location: ../catalog.php");
    } else if ($count < 0) {
        // all / semua barang
        unset($_SESSION['kategori']);
        $_SESSION['startNum']=$startNum;
        $_SESSION['endNum']=$endNum;
        $_SESSION['curPage']=$curPage;
        header("location: ../catalog.php");
    }
}
?>
